#define ACTIVE 1
#define DESTROY 0

class BULLET : public ENEMY {
    public:
        BULLET();
        ~BULLET();
        
        //properties
        IMAGE * image;
        bool goingLeft;
        bool goingRight;
        bool exists;
        int speed;
        int id;
        
        //behaviors
        int Update();
        IMAGE * LoadBullet(int id);
        void ShootNextBullet(const int facing, int x, int y);
        
    private:
        void SpriteAnimate();
        
}bullet[20], create;

int BULLET::Update()
{
    if(exists){
      //draw bullet
      if(!image){oslDebug("ERROR WITH BULLET! CANNOT SHOOT!!"); return DESTROY;}
      oslDrawImage(image);
    
      //move bullet
      if(goingLeft) image->x -= speed;
      if(goingRight) image->x += speed;
    
      //check if bullet is gone
      if(image->x > 485 || image->x < -5)return DESTROY;
    }
    
    else {
        goingLeft = false;
        goingRight = false;
        id = 1;
        speed = 7;
        
        if(image != NULL)oslDeleteImage(image);
    }
    
    return ACTIVE;
}

void BULLET::ShootNextBullet(const int facing, int x, int y)
{
    
    for(int i = 0; i < 20; i++)
    {
        if(bullet[i].exists == 0)
        {
            bullet[i].exists = true;
            bullet[i].id = equippedWeapon;
            bullet[i].speed = 7;
            bullet[i].image = LoadBullet(bullet[i].id);
            bullet[i].image->x = x;
            bullet[i].image->y = y;
            if(facing == 0)bullet[i].goingLeft = true;
            else bullet[i].goingRight = true;
            break;
        }
    }
            
    return;
}

IMAGE * BULLET::LoadBullet(int id)
{
    IMAGE * image = NULL;
    if(id == DEFAULT_0) image = oslLoadImageFilePNG((char*)"img/bullets/3783.png", OSL_IN_RAM, OSL_PF_5551);
    else if(id == DEFAULT_1) image = oslLoadImageFilePNG((char*)"img/bullets/3784.png", OSL_IN_RAM, OSL_PF_5551);
    else if(id == DEFAULT_2) image = oslLoadImageFilePNG((char*)"img/bullets/3785.png", OSL_IN_RAM, OSL_PF_5551);
    else if(id == DEFAULT_3) image = oslLoadImageFilePNG((char*)"img/bullets/3786.png", OSL_IN_RAM, OSL_PF_5551);
    else oslWarning("ERROR! UNABLE TO LOAD BULLET IMAGE!");
    
    if(!image)oslFatalError("ERROR image returned NULL");
    
    return image;
}

void BULLET::SpriteAnimate()
{
    return;
}

BULLET::BULLET()
{
    exists = false;
    goingLeft = false;
    goingRight = false;
    id = 1;
    
    return;
}

BULLET::~BULLET()
{
    return;
}
